package com.example.casper.Experiment2024.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.casper.Experiment2024.R;
import com.example.casper.Experiment2024.utils.BookModel;

public class BookDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_detail);
        EditText et = findViewById(R.id.et);
        et.setText(getIntent().getStringExtra("bookName"));
        findViewById(R.id.btn).setOnClickListener(v -> {
            String bookName = et.getText().toString().trim();
            if (TextUtils.isEmpty(bookName)) {
                Toast.makeText(this, "请设置图书名称", Toast.LENGTH_SHORT).show();
                return;
            }

            BookModel.saveDataByPosition(this, getIntent().getStringExtra("operate"), bookName, getIntent().getIntExtra("position", 0));
            setResult(666);
            finish();
        });
    }
}